// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.IndexLifecycleManagement;

public sealed partial class AllocateAction
{
	[JsonInclude, JsonPropertyName("exclude")]
	public IDictionary<string, string>? Exclude { get; set; }
	[JsonInclude, JsonPropertyName("include")]
	public IDictionary<string, string>? Include { get; set; }
	[JsonInclude, JsonPropertyName("number_of_replicas")]
	public int? NumberOfReplicas { get; set; }
	[JsonInclude, JsonPropertyName("require")]
	public IDictionary<string, string>? Require { get; set; }
	[JsonInclude, JsonPropertyName("total_shards_per_node")]
	public int? TotalShardsPerNode { get; set; }
}

public sealed partial class AllocateActionDescriptor : SerializableDescriptor<AllocateActionDescriptor>
{
	internal AllocateActionDescriptor(Action<AllocateActionDescriptor> configure) => configure.Invoke(this);

	public AllocateActionDescriptor() : base()
	{
	}

	private IDictionary<string, string>? ExcludeValue { get; set; }
	private IDictionary<string, string>? IncludeValue { get; set; }
	private int? NumberOfReplicasValue { get; set; }
	private IDictionary<string, string>? RequireValue { get; set; }
	private int? TotalShardsPerNodeValue { get; set; }

	public AllocateActionDescriptor Exclude(Func<FluentDictionary<string, string>, FluentDictionary<string, string>> selector)
	{
		ExcludeValue = selector?.Invoke(new FluentDictionary<string, string>());
		return Self;
	}

	public AllocateActionDescriptor Include(Func<FluentDictionary<string, string>, FluentDictionary<string, string>> selector)
	{
		IncludeValue = selector?.Invoke(new FluentDictionary<string, string>());
		return Self;
	}

	public AllocateActionDescriptor NumberOfReplicas(int? numberOfReplicas)
	{
		NumberOfReplicasValue = numberOfReplicas;
		return Self;
	}

	public AllocateActionDescriptor Require(Func<FluentDictionary<string, string>, FluentDictionary<string, string>> selector)
	{
		RequireValue = selector?.Invoke(new FluentDictionary<string, string>());
		return Self;
	}

	public AllocateActionDescriptor TotalShardsPerNode(int? totalShardsPerNode)
	{
		TotalShardsPerNodeValue = totalShardsPerNode;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ExcludeValue is not null)
		{
			writer.WritePropertyName("exclude");
			JsonSerializer.Serialize(writer, ExcludeValue, options);
		}

		if (IncludeValue is not null)
		{
			writer.WritePropertyName("include");
			JsonSerializer.Serialize(writer, IncludeValue, options);
		}

		if (NumberOfReplicasValue.HasValue)
		{
			writer.WritePropertyName("number_of_replicas");
			writer.WriteNumberValue(NumberOfReplicasValue.Value);
		}

		if (RequireValue is not null)
		{
			writer.WritePropertyName("require");
			JsonSerializer.Serialize(writer, RequireValue, options);
		}

		if (TotalShardsPerNodeValue.HasValue)
		{
			writer.WritePropertyName("total_shards_per_node");
			writer.WriteNumberValue(TotalShardsPerNodeValue.Value);
		}

		writer.WriteEndObject();
	}
}